package com.linyaonan.leetcode.medium._114;

/**
 * @author: Lin
 * @date: 2020/1/18
 */
public class FlattenBinaryTree {
    TreeNode child = null;
    public void flatten(TreeNode root) {
        dfsAndBuild(root);
    }

    private void dfsAndBuild(TreeNode node) {
        if (node != null) {
            // 后序遍历
            dfsAndBuild(node.right);
            dfsAndBuild(node.left);
            // 右节点赋值
            node.right = child;
            // 左节点清除内容
            node.left = null;
            child = node;
        }
    }
}
